/*
 * @Author: zhangweixin 
 * @Date: 2018-11-19 19:46:18 
 * @Last Modified by: zhangweixin
 * @Last Modified time: 2018-11-20 11:28:55
 */
import {
  GET_USER_INFO_REQUEST,
  GET_USER_INFO_SUCCESS,
  GET_USER_INFO_FAIL
} from '../constants/actionTypes';

function getUserInfoRequest(){
  return {
    type:GET_USER_INFO_REQUEST
  }
}

function getUserInfoSuccess(userInfo){
  return {
    type:GET_USER_INFO_SUCCESS,
    userInfo:userInfo
  }
}

function getUserInfoFail(){
  return {
    type:GET_USER_INFO_FAIL
  }
}
export function getUserInfo() {
  return function (dispatch) {
      dispatch(getUserInfoRequest());

      return fetch('http://localhost:8080/api/user.json')
          .then((response => {
              return response.json()
          }))
          .then((json) => {
                  dispatch(getUserInfoSuccess(json))
              }
          ).catch(
              () => {
                  dispatch(getUserInfoFail());
              }
          )
  }
}